package com.controller;

import com.model.Data;
import com.service.DataService;
import com.tool.ResponseMessage;
import com.tool.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 编写者：粱嘉宝
 * 编写时间：2019-5-29
 * 类模块描述：查询及相关增删改
 */
@RestController(value = "/Data")
public class DataController {
    @Autowired
    private DataService dataService;
    /*查询数据*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "/getDid")
    public Data getDid(int did){return dataService.selectByPrimaryKey(did);}
    /*查询数据*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "/getAllD")
    public ResponseMessage getD(){
        System.out.println("调用角色全部信息");
        Map<String, List> map = new HashMap<>();
        map.put("list",dataService.getAllD());
        return Result.success("200",map);}
    /*删除数据*/
    @CrossOrigin /*跨越访问*/
    @RequestMapping(value = "delD",method = RequestMethod.GET)
    public int delD (int did){return dataService.delD(did);}
    /*添加数据*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "addD",method = RequestMethod.PUT)
    public int addD(@RequestBody Data datamodel){
        if (datamodel!=null){}
        else
        {}
        return dataService.insertD(datamodel);}
}
